def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def word_to_digit(word):
    digit_map = {
        'zero': '0',
        'one': '1',
        'two': '2',
        'three': '3',
        'four': '4',
        'five': '5',
        'six': '6',
        'seven': '7',
        'eight': '8',
        'nine': '9'
    }
    return digit_map.get(word, '')

def nearest_prime(n):
    if n < 2:
        return 2
    lower = n - 1
    while not is_prime(lower):
        lower -= 1
    upper = n + 1
    while not is_prime(upper):
        upper += 1
    if n - lower <= upper - n:
        return lower
    else:
        return upper


def main():
    words = input().split()
    if len(words) != 3:
        print("Wrong input")
        return
    num_str = ''.join([word_to_digit(word) for word in words])
    if not num_str.isdigit() or not 100 <= int(num_str) <= 999:
        print("Wrong input")
        return
    num = int(num_str)
    print(nearest_prime(num))

if __name__ == "__main__":
    main()
